#ifndef GPSMANAGER_H
#define GPSMANAGER_H

#include <QtGui>

#include <QGeoPositionInfoSource>
#include <QGeoSatelliteInfoSource>
#include <QGeoSatelliteInfo>
QTM_USE_NAMESPACE

#include "gps_point.h"
#include "gps_dop.h"
#include "controls/fttabwidget.h"
#include "controls/ftpushbutton.h"

class FTCompass;
class FTSatelliteMap;
class FTLabel;
class FTList;
class FTLatLonEdit;

class GpsManager : public FTTabWidget
{
    Q_OBJECT
public:
    enum gps_status { disabled, fix, no_fix };

    explicit GpsManager();
    ~GpsManager();

    // Return some internal data
    GPS_point currentPosition() const;
    GpsManager::gps_status gpsStatus() const;
    GPS_dop dop() const;

signals:
    // Emitted when the GPS has changed the status
    void gpsStatusChange(GpsManager::gps_status);
    // Emitted every new GPS point received.
    void gpsUpdate( GPS_point );

public slots:
    // Initialize and shutdown the GPS
    void gpsStatusToggle();

private slots:
    void gpsTimeout();
    void gpsUpdateMe(QGeoPositionInfo);
    void satelliteUpdateUse( QList<QGeoSatelliteInfo> );
    void satelliteUpdateAll( QList<QGeoSatelliteInfo> );
    void startGps();
    void stopGps();
    void configGpsStarter( GpsManager::gps_status );
    void updateDopLabels(int);

private:
    // Store the current position
    GPS_point _currentPosition;
    // Status of GPS (disabled, fixed, not fixed)
    GpsManager::gps_status _gpsStatus;
    // Dilution Of Precision
    GPS_dop _dop;
    // start / stop GPS
    FTPushButton* gpsStarter;

    // Helpers to improve code readability
    void buildDataPage();
    void buildSatPage();

    // GPS data page:
    QWidget* data_page;
    FTLabel* precision_label;
    FTLabel* precision;
    FTLabel* altitude_label;
    FTLabel* altitude;
    FTLatLonEdit* latlon;
    FTLabel* speed_label;
    FTLabel* speed;
    FTCompass* compass;

    // Satellites info page
    QWidget* sat_page;
    FTLabel* dop_label;
    FTLabel* dop_values;
    FTLabel* satinfo_label;
    FTLabel* satinfo;
    FTTabWidget* satdata;
    FTList* satlist;
    FTSatelliteMap* satellite_map;

    // The object to access the GPS device
    QGeoPositionInfoSource* gps_location_source;
    QGeoSatelliteInfoSource* gps_satellites_source;

    QLayout* createHorizontal();
    QLayout* createVertical();
};

#endif // GPSMANAGER_H
